/*
** exec_com2.c for 42sh in /home/lingla_j/work/projet/42sh/43sh
** 
** Made by julien linglain
** Login   <lingla_j@epitech.net>
** 
** Started on  Thu Apr  5 15:35:13 2012 julien linglain
** Last update Thu Apr  5 15:53:58 2012 julien linglain
*/

#include	<stdlib.h>
#include	<unistd.h>
#include	<sys/types.h>
#include	<sys/wait.h>
#include	"mysh.h"

int		my_exec_with_path(char **av)
{
  pid_t         pid;
  int           status;
  pid_t         w;
  extern char   **environ;

  if ((pid = !fork()))
    {
      if (execve(av[0], av, environ) == -1)
	my_puterror("Command not found.\n");
      exit(0);
    }
  else
    {
      w = waitpid(pid, &status, WUNTRACED | WCONTINUED);
      if (w == -1)
        {
          my_puterror("Error on Waitpid.\n");
          exit(EXIT_FAILURE);
        }
      if (WEXITSTATUS(status) == 2)
        return (EXIT_FAILURE);
    }
  return (EXIT_SUCCESS);
}

int		my_path_var_empty()
{
  my_puterror("Variable path doesn't exist. The command can not be executed."
	      " Unless you specify the entire path.\n");
  return (EXIT_FAILURE);
}

int		check_if_path(char *s)
{
  int		i;
  int		slash;

  i = 0;
  slash = 0;
  while (s[i] != '\0')
    {
      if (s[i] == '/')
	slash++;
      i++;
    }
  if (slash > 0)
    return (1);
  else
    return (0);
}
